<%@page import="it.sauronsoftware.base64.Base64"%>
<%@page import="multiface.awwadco.jpa.Utente"%>
<style type="text/css">
    .des_hp{display: none}
</style>
<script type="text/javascript">
    $("#homepage").live('click',function() {
        if($("#homepage").attr('checked') == "checked"){
            $(".des_hp").fadeIn(400);
        }else{
            $(".des_hp").fadeOut(400);
        }
    });
    $(document).ready(function(){
        $("#formBox").validate();
    });
</script>

<%@page import="multiface.web.util.PagerList"%>
<%@page import="javax.persistence.Query"%>
<%@page import="java.util.LinkedList"%>
<%@page import="multiface.awwadco.jpa.PersistenceManager"%>
<%
    Utente ut = (Utente) session.getAttribute("admin");
    if (ut == null) {
        response.sendRedirect(multiface.web.util.ServletUtils.getBaseUrl(request) + "/admin/index.jsp?err=y");
    }
%>

<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@page import="javax.persistence.RollbackException"%>
<%@page import="javax.persistence.EntityManager"%>
<%@page import="javax.persistence.Persistence"%>
<%@page import="javax.persistence.EntityManagerFactory"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<script type="text/javascript">
    // codice javascript per il validator dei campi 
</script>

<div class="box">
    <form class="formBox" id="formBox" method="post" action="">
        <%
            EntityManagerFactory emf = PersistenceManager.getInstance().getEntityManagerFactory();
            EntityManager em = emf.createEntityManager();

            String uid = request.getParameter("uid");

            Utente p = em.createNamedQuery("Utente.findByIdutente", Utente.class).setParameter("idutente", Integer.parseInt(uid)).getSingleResult();

            em.close();
            //emf.close();
        %>
        <div class="title">Modifying User: <%=p.getNome()%> <%=p.getCognome()%></div>
        <br>
        <input id="idutente" name="idutente" type="hidden" value="<%=uid%>"/>

        <div class="inputs">
            <label for="nome">Name</label>
            <input name="nome" id="nome" maxlength="255" class="required" type="text" value="<%=p.getNome()%>"/>
        </div>

        <div class="inputs">
            <label for="cognome">Surname</label>
            <input name="cognome" id="cognome" maxlength="255" class="required" type="text" value="<%=p.getCognome()%>"/>
        </div>

        <div class="inputs">
            <label for="user">Username</label>
            <input name="user" id="user" class="required" maxlength="255" type="text" value="<%=p.getUser()%>"/>
        </div>

        <div class="inputs">
            <label for="password">Password</label>
            <input name="password" id="password" class="required" maxlength="255" type="password" value="<%=Base64.decode(p.getPassword())%>"/>
        </div>

        <%--<div class="inputs">
            <label for="tipo">Type of account</label>
            <select name="tipo" class="required" id="tipo">
                <option value="null">Select a type of account...</option>
                <%
                    if (p.getTipo().toUpperCase().equals("AMMINISTRATORE")) {
                %>
                <option value="AMMINISTRATORE" selected="true">Administrator</option>
                <%            }
                %>
            </select>
        </div>--%>
        <input name="tipo" id="tipo" maxlength="255" type="hidden" value="AMMINISTRATORE"/>
    </form>
</div>